//
//  RunLoopTest.m
//  MutlThreads
//
//  Created by 赵梁 on 2018/1/8.
//  Copyright © 2018年 赵梁. All rights reserved.
//

#import "RunLoopTest.h"

#import <UIKit/UIKit.h>

@implementation RunLoopTest


- (void)timerRunInDefaultRunLoopMode
{
    // 定义一个定时器，约定两秒之后调用self的run方法
    NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:YES];
    
    // 将定时器添加到当前RunLoop的NSDefaultRunLoopMode下
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
//    NSLog(@"*********\n%@",runLoop);
}

- (void)timerRunInUITrackingRunLoopMode
{
    // 定义一个定时器，约定两秒之后调用self的run方法
    NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run2) userInfo:nil repeats:YES];
    
    // 将定时器添加到当前RunLoop的NSDefaultRunLoopMode下
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:UITrackingRunLoopMode];
//    NSLog(@"*********\n%@",runLoop);
}

- (void)timerRunInNSRunLoopCommonModes
{
    // 定义一个定时器，约定两秒之后调用self的run方法
    NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run3) userInfo:nil repeats:YES];
    
    // 将定时器添加到当前RunLoop 并指定runloop的运行模式
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSRunLoopCommonModes];
    NSLog(@"*********\n%@",runLoop);
}

- (void)run
{
    NSLog(@"---DefaultRunLoopMode");
}

- (void)run2
{
    NSLog(@"---UITrackingRunLoopMode");
}

- (void)run3
{
    NSLog(@"---NSRunLoopCommonModes");
}

@end
